$(function () {
    initEvent();
    getUserInfo();
});

function initEvent() {
    // $("#submitMsg").off('click').on('click', function () {
    //     submitMsg();
    // });
}

//获取位置
function getUserInfo(){
    var code = getParam('code');

    if(code){
        alert(1);
        var geoc = new BMap.Geocoder();
        var geolocation = new BMap.Geolocation();
        geolocation.getCurrentPosition(function(r){
            if(this.getStatus() == BMAP_STATUS_SUCCESS){
                var lng = r.longitude;
                var lat = r.latitude;
                var address = r.address.city;
                alert(code);
                alert(lng);
                alert(lat);
                alert(address);

                // location.href = "/api/c/init/city/"+r.address.city+"/lng/"+lng+"/lat/"+lat+"/code/"+code;
            }else {
                alert("您的浏览器不支持获取地理位置。");
            }
        },{enableHighAccuracy: true});

    }else{
        alert(2);
        //测试微信跳转
        var url = encodeURI("http://release.weixin.mayi121.com/location");
        var scope = "snsapi_userinfo";
        document.location.href= "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd65849ebe359e61e&redirect_uri="+url+"&response_type=code&scope="+scope+"&state=STATE#wechat_redirect"

    }

    function getParam(key){
        var params = location.href;
        params = params.split("?")[1];

        if(!params){
            return false;
        }

        params = params.split("&");
        for(k in params){
            var arr = params[k].split('=');
            if(arr[0] == key) {
                return arr[1];
            }
        }
    }

    function Traversal(object){
        var str = '';
        for(var i in object){ //遍历object
            str += '\n'+(i+' : '+object[i]);  //  i+' : '+object[i] ---> 获取属性名 和 属性值
        }
        alert(str);
    }

}

function submitMsg() {

}













